package org.example.seata.bs.product.controller;

import feign.RequestTemplate;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.example.seata.bs.api.feign.account.RemoteAccountService;
import org.example.seata.bs.api.vo.account.AccountVo;
import org.example.seata.common.core.constant.SecurityConst;
import org.example.seata.common.core.util.ApiResp;
import org.example.seata.common.security.config.resource.Inner;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hzq
 * @date 2021/12/15 15:05
 */
@RestController
@RequestMapping("/account")
@AllArgsConstructor
public class AccountController {

    private final RemoteAccountService remoteAccountService;

    /**
     * 测试 服务调用 token 用户信息是否拷贝传递
     *
     * @return 用户信息
     * @see org.springframework.cloud.openfeign.FeignAutoConfiguration.Oauth2FeignConfiguration#oauth2FeignRequestInterceptor(OAuth2ClientContext, OAuth2ProtectedResourceDetails) 需配置客户端信息才生效
     * @see org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptor#apply(RequestTemplate)
     */
    @GetMapping
    @ApiOperation("获取用户信息")
    public ApiResp<AccountVo> getInfo() {
        return remoteAccountService.getInfo();
    }

    @Inner(false)
    @PutMapping
    @ApiOperation("获取用户信息")
    public ApiResp putInfo() {
        return remoteAccountService.putInfo(SecurityConst.FROM_IN);
    }
}
